package www.ym.com.utils;

import org.apache.commons.lang.StringUtils;

import java.text.SimpleDateFormat;
import java.util.Date;

public class DateConversion {
    /**
     * 国际标准时间格式String转Date
     * 2023-04-20T16:00:00.000Z
     */
    public static Date getDateByStringBIH(String date){
        if (StringUtils.isNotEmpty(date)) {
            date = date.replace("Z", " UTC");
            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS Z");
//            SimpleDateFormat chinaSdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
            SimpleDateFormat chinaSdf = new SimpleDateFormat("yyyy-MM-dd");
            try {
                Date time = sdf.parse(date);
                String result = chinaSdf.format(time);
                Date chinaDate = chinaSdf.parse(result);
                return chinaDate;
            } catch (Exception e) {
                throw new RuntimeException("转换为日期类型错误getDateByStringBIH");
            }
        }else {
            return null;
        }
    }
}
